package problems.daily;

/**
 * @author dubulingbo, 2023/4/6 12:53.
 */
public class DT1017 {
    /**
     * https://leetcode.cn/problems/convert-to-base-2/
     */
    public String baseNeg2(int n) {
        StringBuilder ret = new StringBuilder();
        while (n != 0) {
            int k = n & 1;
            ret.append(k);
            // 类似进位
            n -= k;
            n /= -2;
        }

        return ret.reverse().toString();
    }

    public static void main(String[] args) {
        DT1017 test = new DT1017();
        System.out.println(test.baseNeg2(2));
        System.out.println(test.baseNeg2(3));
        System.out.println(test.baseNeg2(4));
        System.out.println(test.baseNeg2(5));
        System.out.println(test.baseNeg2(6));
        System.out.println(test.baseNeg2(7));
        System.out.println(test.baseNeg2(Integer.MAX_VALUE));
    }
}
